package com.dt.common.validation;

import lombok.Getter;

@Getter
public class ValidatorConfiguration {

	/**
	 * 检查时是否快速失败
	 */
	private boolean fastFailure = true;

	/**
	 * meta bean class name，用于扫描validation annotation
	 */
	private Class<?> metaClass;

	/**
	 * 用于重定义validation规则的资源，传入classpath路径
	 */
	private String overridedDefinitionResource;

	/**
	 * 重定义资源文件编码
	 */
	private String resourceCharset = "utf-8";

	/**
	 * 是否支持检查Map对象中属性，此功能暂时未开完成
	 */
	private boolean supportMapObject = false;

	private ValidatorConfiguration() {
	}

	public static Builder builder() {
		return new ValidatorConfiguration().new Builder();
	}

	public Validator byFactory(ValidatorFacotry factory) {
		return factory.build(this);
	}

	public class Builder {
		private Builder() {
		}

		public ValidatorConfiguration build() {
			return ValidatorConfiguration.this;
		}

		public Builder ofOverridedDefinitionResource(String overridedDefinitionResource) {
			ValidatorConfiguration.this.overridedDefinitionResource = overridedDefinitionResource;
			return this;
		}

		public Builder ofFastFailure(boolean isFastFailure) {
			ValidatorConfiguration.this.fastFailure = isFastFailure;
			return this;
		}

		public Builder ofMetaClass(Class<?> metaClass) {
			ValidatorConfiguration.this.metaClass = metaClass;
			return this;
		}

		public Builder ofSupportMapObject(boolean supportMapObject) {
			ValidatorConfiguration.this.supportMapObject = supportMapObject;
			return this;
		}

		public Builder ofResourceCharset(String resourceCharset) {
			ValidatorConfiguration.this.resourceCharset = resourceCharset;
			return this;
		}

	}

}
